import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:part_time_job_pro/common/index.dart';
import 'package:part_time_job_pro/pages/offer/part_offer_list/logic.dart';

class PartOfferListPage extends StatelessWidget {
  PartOfferListPage({Key? key}) : super(key: key);

  //路由地址
  static const String routeName = "/offer/part/list";
  final logic = Get.find<PartOfferListLogic>();
  final state = Get.find<PartOfferListLogic>().state;
  final ScrollController scrollController = ScrollController();

  @override
  Widget build(BuildContext context) {
    return GetBuilder<PartOfferListLogic>(builder: (logic) {
      return Container(
        height: 1.sh,
        color: AppColor.norGray01Color,
        child: Stack(
          children: [
            Positioned(top: 60, left: 0, child: buildOfferListView()),
            Positioned(top: 0, left: 0, child: buildTopButtonView()),
          ],
        ),
      );
    });
  }

  //处理列表部分
  Widget buildOfferListView() {
    return Container(
      width: 1.sw,
      height: 1.sh,
      alignment: Alignment.centerLeft,
      padding: EdgeInsets.only(top: 0.r, bottom: 100.r),
      child: EasyRefresh(
        header: CommonUtil.getClassicHeader(refreshedText: "刷新完成"),
        footer: CommonUtil.getClassicalFooter(loadedText: "加载完成"),
        onRefresh: () async {
          logic.initPartTimeJobList();
        },
        onLoad: () async {},
        child: CustomScrollView(
          scrollDirection: Axis.vertical,
          slivers: <Widget>[
            //处理滚动banner
            // SliverToBoxAdapter(
            //   child: buildListBannerView(),
            // ),
            SliverList(delegate: SliverChildBuilderDelegate((context, index) {
              return buildSingleListItem(state.partTimeJobList[index]);
            },childCount: state.partTimeJobList.length)),
            //处理列表部分
            // SliverToBoxAdapter(
            //   child: Column(
            //     mainAxisAlignment: MainAxisAlignment.start,
            //     crossAxisAlignment: CrossAxisAlignment.start,
            //     children: state.partTimeJobList.map((item) {
            //       return buildSingleListItem(item);
            //     }).toList(),
            //   ),
            // ),
          ],
        ),
      ),
    );
  }

  //处理列表数据项
  Widget buildSingleListItem(PartTimeJob jobData) {
    return Container(
      height: 80.h,
      width: 1.sw,
      color: AppColor.norWhiteColor,
      margin: EdgeInsets.only(top: 5.h),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Stack(
            children: [
              Container(
                width: 60.w,
              ),
              Positioned(
                  left: 15.w,
                  top: 20.h,
                  child: Image.asset(
                    AssetsImages.jzJobIcon,
                    height: 30.h,
                  ))
            ],
          ),
          Expanded(
              child: Column(
            mainAxisAlignment: MainAxisAlignment.start,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Padding(
                  padding: EdgeInsets.only(top: 4.h),
                  child: Text(
                    "${jobData.jobName}",
                    style: TextStyle(
                        fontSize: 14.sp,
                        fontWeight: FontWeight.bold,
                        color: AppColor.norBlack01Colors),
                  )),
              Row(
                children: [
                  Icon(
                    Icons.schedule,
                    size: 12.sp,
                    color: AppColor.norGray02Color,
                  ),
                  Padding(
                      padding: EdgeInsets.symmetric(horizontal: 3.w),
                      child: Text(
                        "${jobData.createTime?.substring(0, 10)}",
                        style: TextStyle(
                            fontSize: 12.sp,
                            fontWeight: FontWeight.normal,
                            color: AppColor.norGray02Color),
                      )),
                  Icon(
                    Icons.remove_red_eye_outlined,
                    size: 12.sp,
                    color: AppColor.norGray02Color,
                  ),
                  Padding(
                      padding: EdgeInsets.symmetric(horizontal: 3.w),
                      child: Text(
                        "0",
                        style: TextStyle(
                            fontSize: 12.sp,
                            fontWeight: FontWeight.normal,
                            color: AppColor.norGray02Color),
                      ))
                ],
              ),
              Row(
                children: [
                  Icon(
                    Icons.room_outlined,
                    size: 12.sp,
                    color: AppColor.norGray02Color,
                  ),
                  Padding(
                      padding: EdgeInsets.symmetric(horizontal: 3.w),
                      child: Text(
                        "${jobData.cityName} ${jobData.areaName} ",
                        style: TextStyle(
                            fontSize: 12.sp,
                            fontWeight: FontWeight.normal,
                            color: AppColor.norGray02Color),
                      )),
                  Padding(
                      padding: EdgeInsets.symmetric(horizontal: 3.w),
                      child: Text.rich(//实现换行
                          TextSpan(children: [
                        TextSpan(
                          text: "招聘人数",
                          style: TextStyle(
                              color: AppColor.norGray02Color, fontSize: 12.sp),
                        ),
                        TextSpan(
                          text: " 0/${jobData.applyNum}",
                          style: TextStyle(
                              color: AppColor.norRedColors, fontSize: 12.sp),
                        ),
                      ]))),
                ],
              ),
            ],
          ))
        ],
      ),
    );
  }

  //处理顶部按钮
  Widget buildTopButtonView() {
    return Container(
      width: 1.sw,
      alignment: Alignment.center,
      padding: EdgeInsets.only(top: 13.h),
      child: SingleChildScrollView(
        scrollDirection: Axis.horizontal,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: state.offerStatusList
              .map((data) => buildSingleButton(data))
              .toList(),
        ),
      ),
    );
  }

  //处理单个按钮
  Widget buildSingleButton(data) {
    return Container(
      alignment: Alignment.center,
      padding: EdgeInsets.symmetric(vertical: 3.r, horizontal: 8.r),
      margin: EdgeInsets.only(left: 5.r),
      decoration: BoxDecoration(
          color: AppColor.norGray01Color,
          border: Border.all(
            width: 1.r,
            color: AppColor.norGray02Color,
          ),
          borderRadius: BorderRadius.circular(20.r)),
      child: Text("待支付 0",
          style: TextStyle(color: AppColor.norGray04Color, fontSize: 11.sp)),
    );
  }

  //处理swiper部分
  Widget buildListBannerView() {
    return Container(
      width: 1.sw,
      alignment: Alignment.center,
      margin: EdgeInsets.only(top: 0.r, bottom: 0.r),
      child: Image.asset(AssetsImages.offerListBanner),
    );
  }
}
